<?php
	class Monetization extends Model_Abstract{
		
		public function getMonetizationByIds(array $ids){
			try{
				if(!is_array($ids)){
					return false;
				}
				$condition = implode(', ', $ids);
				$sql = "select * from monetizations where id in (" . $condition . ")";
				$result = $this->_connection->query($sql);
				if(count($result) == 0){
					return false;
				}else{
					return $result;
				}
			}catch (Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function getSecretKeyById($id){
			try{
				$sql = "select secret_key from monetizations where id=? limit 1";
				$result = $this->_connection->query($sql, array($id));
				if(count($result) == 0){
					return false;
				}else{
					return $result[0]['secret_key'];
				}
			}catch (Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
			
		}

		public function getMonetizationByID($id)
		{
			try
			{
				$sql = "select * from monetizations where id=?";
				$result = $this->_connection->query($sql, array($id));
				if(count($result) == 0)
				{
					return false;
				}
				else
				{
					return $result[0];
				}
			}
			catch (Exception $e)
			{
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function getMonetizationFactor($key){
			try
			{
				$sql = "select v from configs where k=?";
				$result = $this->_connection->query($sql, array($key));
				if(count($result) == 0)
				{
					return false;
				}
				else
				{
					return $result[0]['v'];
				}
			}
			catch (Exception $e)
			{
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
	
	}